package org.boyan.modules.config.service.a;

import org.apache.commons.lang.StringUtils;
import org.boyan.modules.config.service.DbTableHandleI;

public class a implements DbTableHandleI {
    @Override
    public String getAddColumnSql(org.boyan.modules.config.b.a columnMeta) {
        return " ADD COLUMN " + a(columnMeta) + "";
    }

    @Override
    public String getReNameFieldName(org.boyan.modules.config.b.a columnMeta) {
        return "RENAME COLUMN " + columnMeta.getOldColumnName() + " TO " + columnMeta.getColumnName() + "";
    }

    @Override
    public String getUpdateColumnSql(org.boyan.modules.config.b.a cgformcolumnMeta, org.boyan.modules.config.b.a datacolumnMeta) {
        return " MODIFY " + a(cgformcolumnMeta, datacolumnMeta) + "";
    }

    @Override
    public String getMatchClassTypeByDataType(String dataType, int digits) {
        String str = "";
        if (dataType.equalsIgnoreCase("varchar2")) {
            str = "string";
        } else if (dataType.equalsIgnoreCase("varchar")) {
            str = "string";
        } else if (dataType.equalsIgnoreCase("nvarchar2")) {
            str = "string";
        } else if (dataType.equalsIgnoreCase("double")) {
            str = "double";
        } else if (dataType.equalsIgnoreCase("number") && digits == 0) {
            str = "int";
        } else if (dataType.equalsIgnoreCase("number") && digits != 0) {
            str = "double";
        } else if (dataType.equalsIgnoreCase("int")) {
            str = "int";
        } else if (dataType.equalsIgnoreCase("Date")) {
            str = "date";
        } else if (dataType.equalsIgnoreCase("Datetime")) {
            str = "date";
        } else if (dataType.equalsIgnoreCase("blob")) {
            str = "blob";
        } else if (dataType.equalsIgnoreCase("clob")) {
            str = "text";
        }
        return str;
    }

    @Override
    public String dropTableSQL(String tableName) {
        return " DROP TABLE  " + tableName.toLowerCase() + " ";
    }

    @Override
    public String getDropColumnSql(String fieldName) {
        return " DROP COLUMN " + fieldName.toUpperCase() + "";
    }

    private String a(org.boyan.modules.config.b.a parama) {
        String str = "(\"" + parama.getColumnName() + "\"";
        if (parama.getColunmType().equalsIgnoreCase("string")) {
            str = str + " varchar2(" + parama.getColumnSize() + ")";
        } else if (parama.getColunmType().equalsIgnoreCase("date")) {
            str = str + " date";
        } else if (parama.getColunmType().equalsIgnoreCase("int")) {
            str = str + " INT";
        } else if (parama.getColunmType().equalsIgnoreCase("double")) {
            str = str + " NUMBER(" + parama.getColumnSize() + "," + parama.getDecimalDigits() + ")";
        } else if (parama.getColunmType().equalsIgnoreCase("bigdecimal")) {
            str = str + " DECIMAL(" + parama.getColumnSize() + "," + parama.getDecimalDigits() + ")";
        } else if (parama.getColunmType().equalsIgnoreCase("text")) {
            str = str + " CLOB ";
        } else if (parama.getColunmType().equalsIgnoreCase("blob")) {
            str = str + " BLOB ";
        }
        str = str + (StringUtils.isNotEmpty(parama.getFieldDefault()) ? (" DEFAULT " + parama.getFieldDefault()) : " ");
        str = str + ("Y".equals(parama.getIsNullable()) ? " NULL" : " NOT NULL");
        str = str + ")";
        return str;
    }

    private String a(org.boyan.modules.config.b.a parama1, org.boyan.modules.config.b.a parama2) {
        String str1 = "";
        String str2 = "";
        if (!parama2.getIsNullable().equals(parama1.getIsNullable())) {
            str2 = parama1.getIsNullable().equals("Y") ? "NULL" : "NOT NULL";
        }
        if (parama1.getColunmType().equalsIgnoreCase("string")) {
            str1 = parama1.getColumnName() + " varchar2(" + parama1.getColumnSize() + ")" + str2;
        } else if (parama1.getColunmType().equalsIgnoreCase("date")) {
            str1 = parama1.getColumnName() + " date " + str2;
        } else if (parama1.getColunmType().equalsIgnoreCase("int")) {
            str1 = parama1.getColumnName() + " INT " + str2;
        } else if (parama1.getColunmType().equalsIgnoreCase("double")) {
            str1 = parama1.getColumnName() + " NUMBER(" + parama1.getColumnSize() + "," + parama1.getDecimalDigits() + ") " + str2;
        } else if (parama1.getColunmType().equalsIgnoreCase("bigdecimal")) {
            str1 = parama1.getColumnName() + " DECIMAL(" + parama1.getColumnSize() + "," + parama1.getDecimalDigits() + ") " + str2;
        } else if (parama1.getColunmType().equalsIgnoreCase("blob")) {
            str1 = parama1.getColumnName() + " BLOB " + str2;
        } else if (parama1.getColunmType().equalsIgnoreCase("text")) {
            str1 = parama1.getColumnName() + " CLOB " + str2;
        }
        str1 = str1 + (StringUtils.isNotEmpty(parama1.getFieldDefault()) ? (" DEFAULT " + parama1.getFieldDefault()) : " ");
        str1 = str1 + str2;
        return str1;
    }

    @Override
    public String getCommentSql(org.boyan.modules.config.b.a columnMeta) {
        return "COMMENT ON COLUMN " + columnMeta.getTableName() + "." + columnMeta.getColumnName() + " IS '" + columnMeta.getComment() + "'";
    }

    @Override
    public String getSpecialHandle(org.boyan.modules.config.b.a cgformcolumnMeta, org.boyan.modules.config.b.a datacolumnMeta) {
        return null;
    }

    @Override
    public String dropIndexs(String indexName, String tableName) {
        return "DROP INDEX " + indexName;
    }

    @Override
    public String countIndex(String indexName, String tableName) {
        return "select count(*) from user_ind_columns where index_name=upper('" + indexName + "')";
    }
}
